package com.chahu.servlet.backend;

import com.alibaba.fastjson.JSON;
import com.chahu.common.Result;
import com.chahu.service.OrderService;
import com.chahu.service.impl.OrderServiceImpl;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.io.PrintWriter;

@WebServlet("/static/backend/order/del")
public class DeleteOrderServlet extends HttpServlet{
	
	OrderService orderService;
	
	@Override
    public void init() throws ServletException {
		orderService = new OrderServiceImpl();
    }

    @Override
    protected void doPost(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        req.setCharacterEncoding("UTF-8");
        resp.setContentType("application/json; charset=utf-8");
        int id = Integer.parseInt(req.getParameter("id"));
        System.out.println("id" + id);
        boolean bsuccess = orderService.deleteById(id);
        
    	try (PrintWriter writer = resp.getWriter()) {
    		if(bsuccess) {
    			writer.write(JSON.toJSONString(Result.success("删除成功！！！")));
    		}else {
    			writer.write(JSON.toJSONString(Result.error("删除失败！！！")));
    		}
        }
    }
}